<template>
	<view class="order">
		<view class="tops">
			<view @tap="titleClick(index)" :class="currentIndex == index ? 'active' :  ''" v-for="(item, index) in titleList"
			 :key="index" class="items">
				{{item}}
			</view>
		</view>
		<view class="product-contain">
			<view class="product">
				<view class="main" v-for="item in orderList" :key="item.userId">
					<view class="top">
						<view>订单编号 {{item.orderId}}</view>
						<view>等待发货</view>
					</view>
					<view class="carList-mains" v-for="(items, index) in item.subList" :key="index">

						<view class="product-center">
							<view class="product-left">
								<view class="imgs">
									<image :src="items.cover_img" mode=""></image>
								</view>
								<view class="content">
									<view class="title">{{items.gname}}</view>
									<view class="desc">
										<view>编号{{items.sku_code}}</view>
										<view>规格{{items.color_text}}</view>
									</view>
								</view>
							</view>
							<view class="product-right">
								<view class="price">{{(items.price || 999) | filterPrice}}</view>
								<view class="price">×{{item.totalCount || 1}}</view>
							</view>
						</view>

					</view>
					<view class="product-bottom">
						<view class="dates">
							时间: {{item.addTime}}
						</view>
						<view class="mains">
							<view class="price">合计: {{item.totalPrice | filterPrice}}</view>
						</view>

					</view>
					<!-- 上面view嵌套加了一层 为了批量提交订单 -->
					<!-- 12 -->
				</view>
			</view>
		</view>
	</view>

	</view>
</template>

<script>
	import {
		getList
	} from '@/network/order/index.js'
	export default {
		data() {
			return {
				orderList: [],
				currentIndex: 0,
				status: '0',
				titleList: ['待付款', '已付款', '已发货', '已收货', '申请退款']
			};
		},
		filters: {
			filterPrice(val) {
				return '¥' + (val / 100)
			}
		},
		methods: {
			titleClick(index) {
				this.currentIndex = index
				console.log(index)
				if (this.currentIndex == 1) {
					this.status = '1';
					this.getLists(this.status)
				} else if (this.currentIndex == 2) {
					this.status = '2'
					this.getLists(this.status)
				} else if (this.currentIndex == 3) {
					this.status = '3'
					this.getLists(this.status)
				} else if (this.currentIndex == 4) {
					this.status = '9'
					this.getLists(this.status)
				} else if (this.currentIndex == 0) {
					this.status = '0';
					this.getLists(this.status)
				}
			},
			getLists(statuss) {
				getList({
					userId: uni.getStorageSync('tokens').id,
					limit: 100,
				}).then(res => {
					console.log(res)
					const arr = res.data.data.list.filter(item => {
						// return item.status == '0'
						return item.status == statuss
						// return item.status == '0'
					})
					console.log(arr)
					this.orderList = arr
				})
			}
		},
		onLoad(options) {
			this.currentIndex = options.status;
			this.status = options.status
			this.getLists(this.status)
		},
		filters: {
			filterPrice(val) {
				return '¥' + (val / 100).toFixed(2)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.order {
		height: 100vh;
		overflow: auto;
		// height: 100%;
		background-color: #F1ECE7;

	}

	.product-contain {
		padding: 40rpx;
	}

	.tops {
		display: flex;
		justify-content: space-around;
		background-color: #354E44;

		.items {
			padding: 20rpx 0;
			color: #fff;
			font-size: 28rpx;
		}

		.active {
			color: #DD524D;
		}
	}

	.product {
		margin-top: 30rpx;

		border-radius: 32rpx;

		.main {
			// width: 336px;
			padding: 0 36rpx;
			margin: 40rpx 0;
			background-color: #fff;

			.top {
				font-size: 26rpx;
				display: flex;
				justify-content: space-between;
				padding: 30rpx 0;
				border-bottom: 2rpx solid #F1ECE7;
			}

			.product-center {
				display: flex;
				justify-content: space-between;
				padding: 20rpx 0;
				border-bottom: 2rpx solid #F1ECE7;

				.product-left {
					display: flex;

					.imgs {
						width: 162rpx;
						height: 162rpx;
						background-color: pink;
						margin-right: 40rpx;

						image {
							width: 100%;
							height: 100%;
						}
					}

					.content {
						.title {
							font-size: 28rpx;
							margin-bottom: 30rpx;
						}

						.desc {
							font-size: 24rpx;
							color: #8D8D8D;
						}
					}
				}

				.product-right {
					font-size: 26rpx;
				}
			}

			.product-bottom {
				display: flex;
				// justify-content: flex-end;
				justify-content: space-between;
				align-items: flex-start;
				padding: 20rpx 0 40rpx;

				.dates {
					font-size: 24rpx;
				}

				.mains {
					font-size: 26rpx;

					.btn {
						padding: 10rpx;
						border: 2rpx solid #333;
						margin-top: 20rpx;
						border-radius: 16rpx;
						display: flex;
						justify-content: center;
					}
				}
			}
		}
	}
</style>
